package com.train.pattern.strategy.v2.pay;


import com.train.pattern.strategy.v2.pay.way.PayStrategy;
import com.train.pattern.strategy.v2.pay.way.PayStrategyFactory;

public class Order {
    private String uid;
    private String orderId;
    private int amount;
    private double price;


    public Order(String uid, String orderId, int amount) {
        this.uid = uid;
        this.orderId = orderId;
        this.amount = amount;
        this.price=80.5;
    }

    /**
     * 付款
     * @param user  用户
     * @return
     */
    public MsgResult pay(User user) {
        double totalMoney=compute();//计算付款总金额
        Account account=user.getAccount();
        PayStrategy payStrategy= PayStrategyFactory.getPayStrategy(account.getPayWay());
        MsgResult msgResult=payStrategy.pay(account,totalMoney);

        return msgResult;
    }

    /**
     * 计算总价
     * @return
     */
    private double compute(){
        double totalMoney=this.amount * this.price;
        return totalMoney;
    }

    public void setPrice(double price) {
        this.price = price;
    }
}
